﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@model Common.PageInfo
<div class="wrapper wrapper-content animated fadeInUp">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>角色管理</h5>
                    <div class="ibox-tools">
                        <a class="btn btn-primary btn-xs p210" id="insert" action="add"><i class="fa fa-plus-circle fa-fw"></i> 创建新角色</a>
                        <a class="btn btn-warning btn-xs p210" id="modify" action="edit"><i class="fa fa-pencil fa-fw"></i> 编辑</a>
                        <a class="btn btn-danger btn-xs p210" id="delete" action="remove"><i class="fa fa-trash-o fa-fw"></i> 删除</a>
                        <a class="btn btn-info btn-xs p210" id="permission" action="allocation"><i class="fa fa-sheqel fa-fw"></i> 分配权限</a>
                        <a class="reload-link" style="color: #c4c4c4" href="javascript:dig.reload()" data-toggle="tooltip" data-placement="left" title="刷新">
                            <i class="fa fa-repeat fa-lg"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    @using (Ajax.BeginForm("Index", null, new AjaxOptions() { }, new { @id = "form1", @class = "form-horizontal", @method = "get" }))
                    {
                        <div class="row">
                            <div class="col-sm-9">
                                <label>选择系统：</label>
                                <select id="System" name="System" class="form-control input-sm  input-s-sm inline" onchange="submit()">
                                    <option value="" @(ViewData["System"] == null || ViewData["System"].ToString() == "" ? "selected=\"selected\"" : "")>全部系统</option>
                                    @{
                        foreach (var item in ViewData["Systemlist"] as dynamic)
                        {
                            <option value="@item.ID" @(ViewData["System"] != null && ViewData["System"].ToString() != "" && ViewData["System"].ToString() == item.ID ? "selected=\"selected\"" : "")>@item.NAME</option>
                        }
                                    }
                                </select>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    @Html.TextBox("Search", null, new { @class = "input-sm form-control", @placeholder = "请输入查询关键词" })
                                    <span class="input-group-btn">
                                        <button type="submit" onclick="submit()" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <table id="dataTable" class="table table-striped table-bordered table-hover dataTables-example" style="text-align:center;">
                                <thead>
                                    <tr>
                                        <th class="tn" style="width: 50px !important"><input name="checkall" class="icheck_box" type="checkbox" value=""></th>
                                        <th>所属系统</th>
                                        <th>角色名称</th>
                                        <th style="width: 100px !important;">系统预置</th>
                                        <th>创建者</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    @{foreach (var item in Model.List)
                                    {
                                        <tr>
                                            <td class="tn">
                                                @{
                                        if (item.ID != Common.Enums.ClsDic.DicRole["超级管理员"])
                                        {
                                            <input name="checkbox_name" class="icheck_box" type="checkbox" value="@item.ID" />
                                        }                                       
}                                            
                                            </td>
                                            <td>@item.SYSNAME</td>
                                            <td>
                                                @{
                                        if (item.ID != Common.Enums.ClsDic.DicRole["超级管理员"])
                                        {
                                            <a href="javascript:EditRole('@item.ID')" listaction="detail" data-toggle="tooltip" data-placement="right" title="修改">@item.ROLENAME</a>
                                        }
                                        else
                                        {
                                            @item.ROLENAME
                                        }
}
                                               
                                            </td>
                                            <td>@Html.Raw(item.ISCUSTOMSTATUS)</td>
                                            <td>@item.CREATEDATE</td>
                                            <td>@item.USERNAME</td>
                                        </tr>
                                    }
                                    }
                                </tbody>
                            </table>
                        </div>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info">
                                    显示 @Model.BeginPage 到 @Model.EndPage 项，共 @Model.Count 项, 每页显示
                                    <select name="example_length" class="form-control input-sm input-xs-sm inline" onchange="submit()">
                                        <option value="10" @(Model.PageSize == 10 ? "selected" : "")>10</option>
                                        <option value="25" @(Model.PageSize == 25 ? "selected" : "")>25</option>
                                        <option value="50" @(Model.PageSize == 50 ? "selected" : "")>50</option>
                                        <option value="100" @(Model.PageSize == 100 ? "selected" : "")>100</option>
                                    </select> 条记录
                                </div>
                            </div>
                            <div class="col-sm-6">
                                @WebPages.CommonHtmlHelper.PaginationPager(Model.Index, Model.PageSize, Model.Count, 7, Model.Url)
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        $(function () {
            //添加新角色
            $("#insert").click(function () {
                dig.addPage("添加新角色", "/Sys/role/detail?systemId=" + $("#System").val(), 600, 450, function () {
                    if (this.returnValue == 'yes') {
                        location.reload();
                    }
                });
            });
            //列表选择修改
            $('#modify').click(function () {
                var vals = '';
                var num = 0;
                $('input[name="checkbox_name"]:checked').each(function () {
                    vals = $(this).val();
                    num++;
                });
                if (!vals) {
                    dig.error("对不起，请选中您要操作的记录！");
                    return;
                }
                if (num > 1) {
                    dig.error("对不起，每次只能修改一条记录！");
                    return;
                }
                dig.addPage("编辑角色", "/Sys/role/detail/" + vals, 600, 450, function () {
                    if (this.returnValue == 'yes') {
                        location.reload();
                    }
                });
            });
            //分配权限
            $('#permission').click(function () {
                var vals = '';
                var num = 0;
                $('input[name="checkbox_name"]:checked').each(function () {
                    vals = $(this).val();
                    num++;
                });
                if (!vals) {
                    dig.error("对不起，请选中您要操作的记录！");
                    return;
                }
                if (num > 1) {
                    dig.error("对不起，每次只能给一个角色分配权限！");
                    return;
                }
                dig.addPage('分配权限', '/Sys/Permission/PerAllocation/?id=' + vals + '&tp=role', 1000, 500, function () {
                    if (this.returnValue == 'yes') {
                        location.reload();
                    }
                });
            });
        });
        //跳转修改
        function EditRole(n) {
            dig.addPage("编辑角色", "/Sys/role/detail/" + n, 600, 450, function () {
                if (this.returnValue == 'yes') {
                    location.reload();
                }
            });
        }
    </script>
}
